package com.pur.zsms.pmsnmanage.user.web;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lianchuang.service.CoreService;
import com.pur.zsms.common.exception.GenericException;
import com.pur.zsms.common.support.PageController;
import com.pur.zsms.common.support.PaginationSupport;
import com.pur.zsms.common.util.CipherUtil;
import com.pur.zsms.common.util.SignUtil;
import com.pur.zsms.matermanage.mater.vo.MaterVo;
import com.pur.zsms.pmsnmanage.role.po.RolePo;
import com.pur.zsms.pmsnmanage.role.service.IRoleService;
import com.pur.zsms.pmsnmanage.role.vo.RoleVo;
import com.pur.zsms.pmsnmanage.user.po.UserPo;
import com.pur.zsms.pmsnmanage.user.service.IUserService;
import com.pur.zsms.pmsnmanage.user.vo.LdAddressVo;
import com.pur.zsms.pmsnmanage.user.vo.UserVo;
import com.pur.zsms.supplier.service.ISupplierService;
import com.pur.zsms.systemsetting.datadictionary.service.IDataDictionaryService;
import com.pur.zsms.systemsetting.datadictionary.vo.CodeVo;
import com.qq.weixin.mp.aes.AesException;
import com.qq.weixin.mp.aes.WXBizMsgCrypt;

@Controller
@RequestMapping(value = "/user")
public class UserControllor {
	private String token = "weixinCourse";
	private String encodingAESKey = "smYKvlLNrw3BQRb4laoY0oz3Umgoz1tYFHfjXywG5ee";
	private String corpId = "ZSMSL_2013";

	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(UserControllor.class);

	protected int page = 1;

	protected int pageSize = 15;

	PaginationSupport pageList;

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	@Resource(name = "userService")
	private IUserService userService;

	@Resource(name = "coreService")
	private CoreService coreService;

	@Resource(name = "roleService")
	private IRoleService roleService;

	@Resource(name = "dictionaryService")
	private IDataDictionaryService dataDictionaryService;

	@Resource(name = "supplierService")
	private ISupplierService supplierService;

	@RequestMapping(value = "/findUser.do", method = { RequestMethod.POST })
	@ResponseBody
	public String userList(@RequestParam(required = false) String page, @RequestParam(required = false) String rows, UserVo userVo)
			throws GenericException {
		JSONObject json = new JSONObject();
		log.info("----");
		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "10";
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = userService.listUser(pageController, userVo);
		List<UserVo> userList = new ArrayList<UserVo>();
		List items = pageList.getItems();
		List<RoleVo> roles = new ArrayList<RoleVo>();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				UserVo u = new UserVo();
				u.setUserId(((Integer) item[0]).toString());
				roles = userService.listRoleByUserId(u.getUserId());
				String rolenames = "";
				for (int j = 0; j < roles.size(); j++) {
					if (roles.get(j).getChecked().equals("true")) {
						if (rolenames.isEmpty()) {
							rolenames = rolenames + "" + roles.get(j).getRoleName();
						} else {
							rolenames = rolenames + "<br>" + roles.get(j).getRoleName();
						}
					}
				}
				u.setRoleName(rolenames);
				u.setUserName((String) item[1]);
				u.setRealName((String) item[2]);
				u.setOrganName((String) item[3]);
				u.setEmail((String) item[4]);
				u.setIsActive((String) item[5]);
				BigInteger phone = (BigInteger) item[6];
				u.setUserPhone(phone.longValue());
				userList.add(u);
			}
		}
		json.put("success", true);
		json.put("total", pageList.getTotalCount());
		json.put("rows", userList);
		log.info("----" + json.toString());
		return json.toString();
	}

	@RequestMapping(value = "/saveUser.do", method = { RequestMethod.POST })
	@ResponseBody
	public String saveUser(UserVo c, HttpSession session) {
		UserPo lgUser = (UserPo) session.getAttribute("user");
		JSONObject json = new JSONObject();
		try {
			boolean flag = userService.addUser(c, lgUser);
			if (flag) {
				json.put("success", true);

			} else {
				json.put("msg", userService.getMsg());
				json.put("success", false);
			}

		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/preChangePassword.do", method = { RequestMethod.GET })
	public ModelAndView preUpdateMater(String userId) {
		JSONObject json = new JSONObject();
		UserVo userVo = new UserVo();
		userVo.setUserId(userId);
		Map map = new HashMap();
		map.put("userVo", userVo);
		return new ModelAndView("/changepassword", map);
	}

	@RequestMapping(value = "/changePassword.do", method = { RequestMethod.POST })
	@ResponseBody
	public String changePassword(UserVo c) {
		JSONObject json = new JSONObject();
		try {
			UserVo userVo = userService.getUserVoById(c.getUserId());
			userVo.setPassword(c.getPassword());
			userService.updateUser(userVo);
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/preSaveUser.do", method = { RequestMethod.GET })
	public ModelAndView preSaveUser(HttpSession session) {
		JSONObject json = new JSONObject();
		List<RoleVo> roleList = null;
		long companyUser = 0;
		try {
			long userId = ((UserPo) session.getAttribute("user")).getUserId();
			companyUser = userService.getUserLevelPo(userId).getCompanyUser();
			roleList = userService.listAllRole(); // 查询所有角色信息
		} catch (GenericException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("rolelist", roleList);
		map.put("companyUser", companyUser);

		return new ModelAndView("/pmsnmanage/user/addUser", map);
	}

	@RequestMapping(value = "/preUpdateUser.do", method = { RequestMethod.GET })
	public ModelAndView preUpdateUser(String userId) {
		JSONObject json = new JSONObject();
		UserVo user = new UserVo();
		List<RoleVo> list = null;
		try {
			user = userService.listUserByUserId(userId);
			list = userService.listRoleByUserId(userId);
		} catch (GenericException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("user", user);
		map.put("rolelist", list);
		return new ModelAndView("/pmsnmanage/user/editUser", map);
	}

	@RequestMapping(value = "/updateUser.do", method = { RequestMethod.POST })
	@ResponseBody
	public String updateUser(UserVo c, HttpSession session) {
		JSONObject json = new JSONObject();
		try {
			long userId = ((UserPo) session.getAttribute("user")).getUserId();
			long companyUser = userService.getUserLevelPo(userId).getCompanyUser();
			c.setCompanyUser(companyUser);
			userService.updateUser(c);
			userService.updateRoleByUserId(String.valueOf(c.getUserId()), c.getRoles());
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/deleteUser.do", method = { RequestMethod.POST })
	@ResponseBody
	public String deleteUser(String userId) {
		JSONObject json = new JSONObject();
		try {

			System.out.println("--------" + userId);
			userService.deleteUserRoleByUserId(userId);
			userService.deleteUser(userId);
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}

	@RequestMapping(value = "/login.do", method = { RequestMethod.POST })
	public ModelAndView login(HttpSession session, String userName, String password, int mobileFlag) throws Exception {
		java.util.Map<String, Object> map = new java.util.HashMap<String, Object>();
		UserPo userInfo = new UserPo();
		// MD5对用户密码加密
		CipherUtil cipher = new CipherUtil();
		String md5Pwd = cipher.generatePassword(password);
		userInfo = userService.findUserLogon(userName, md5Pwd);
		// IsActive 0:有效；1:无效
		if (mobileFlag == 1) {
			if (userInfo == null) {
				map.put("success", false);
				map.put("user", userInfo);
				map.put("info", "用户或密码错误！");
				return new ModelAndView("/login", map);
			} else if (userInfo != null && "1".equals(userInfo.getIsActive())) {
				map.put("success", false);
				map.put("user", userInfo);
				map.put("info", "用户已停用");
				return new ModelAndView("/login", map);
			} else {
				session.setAttribute("user", userInfo);
				session.setAttribute("mobile", "close");
				return new ModelAndView("redirect:/jsp/main.jsp", map);
			}
		} else if (mobileFlag == 2) {
			if (userInfo == null) {
				map.put("success", false);
				map.put("user", userInfo);
				map.put("info", "用户或密码错误！");
				return new ModelAndView("/indexMobile", map);
			} else if (userInfo != null && "1".equals(userInfo.getIsActive())) {
				map.put("success", false);
				map.put("user", userInfo);
				map.put("info", "用户已停用");
				return new ModelAndView("/indexMobile", map);
			} else {
				session.setAttribute("user", userInfo);
				session.setAttribute("mobile", "open");
				List<RolePo> rolePolist2 = roleService.getRolePoByRoleNameUserId(userInfo, "收银");
				if (rolePolist2 != null && rolePolist2.size() > 0) {
					return new ModelAndView("redirect:/jsp-mobile/cashier/mainMobileForCashier.jsp", map);
				}
				List<RolePo> rolePolist = roleService.getRolePoByRoleNameUserId(userInfo, "供货商");
				if (rolePolist != null && rolePolist.size() > 0) {
					return new ModelAndView("redirect:/jsp-mobile/mainMobileForSupplier.jsp", map);
				} else {
					return new ModelAndView("redirect:/jsp-mobile/mainMobile.jsp", map);
				}
			}
		}
		return new ModelAndView("/login", map);

	}

	@RequestMapping(value = "/menu.do")
	public ModelAndView menu(HttpSession session) throws Exception {
		java.util.Map<String, Object> map = new java.util.HashMap<String, Object>();
		String userId = ((UserPo) session.getAttribute("user")).getUserId() + "";
		map.put("menu", userService.getUserMenuList(userId));
		return new ModelAndView("/menu", map);
	}

	@RequestMapping(value = "/userTestValue.do", method = { RequestMethod.POST })
	public void userTestValue(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter writer;
		try {
			String userTestValue = userService.getUserTestValue();
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
	}

	// 员工选择
	@RequestMapping(value = "/userForShop.do", method = { RequestMethod.POST })
	public void userForShop(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter writer;
		try {
			String userTestValue = userService.getUserForShop();
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
		// return json.toString();
	}

	// 员工选择
	@RequestMapping(value = "/userForSupplierShop.do", method = { RequestMethod.POST })
	public void userForSupplierShop(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter writer;
		try {
			UserPo userInfo = (UserPo) session.getAttribute("user");
			String userTestValue = userService.userForSupplierShop(supplierService.getSupIdByUserId(userInfo.getUserId()));
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
		// return json.toString();
	}

	// 供货商商店选择
	@RequestMapping(value = "/shopForSupplier.do", method = { RequestMethod.POST })
	public void shopForSupplier(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		long userId = ((UserPo) session.getAttribute("user")).getUserId();
		PrintWriter writer;
		try {
			int supId = supplierService.getSupIdByUserId(userId);
			String userTestValue = userService.getShopForSupplier(supId);
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
		// return json.toString();
	}

	// 管理员商店选择
	@RequestMapping(value = "/shopForAdmin.do", method = { RequestMethod.POST })
	@ResponseBody
	public String shopForAdmin(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		// long userId = ((UserPo) session.getAttribute("user")).getUserId();
		try {
			long userId = ((UserPo) session.getAttribute("user")).getUserId();
			String userTestValue = userService.getShopForAdmin(userId);
			json.put("stringJson", userTestValue);

		} catch (GenericException e) {
			e.printStackTrace();
		}
		return json.toString();
	}

	// 经理商店选择
	@RequestMapping(value = "/shopForManager.do", method = { RequestMethod.POST })
	public void shopForManager(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		long userId = ((UserPo) session.getAttribute("user")).getUserId();
		PrintWriter writer;
		try {
			String userTestValue = userService.getShopForManager(userId);
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
		// return json.toString();
	}

	// 财务商店选择
	@RequestMapping(value = "/shopForAccountant.do", method = { RequestMethod.POST })
	public void shopForAccountant(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		long userId = ((UserPo) session.getAttribute("user")).getUserId();
		PrintWriter writer;
		try {
			String userTestValue = userService.shopForAccountant(userId);
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
		// return json.toString();
	}

	@RequestMapping(value = "/userTestValueForSuppOrder.do", method = { RequestMethod.POST })
	@ResponseBody
	public String userTestValueForSuppOrder(String orderDate, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		long userId = ((UserPo) session.getAttribute("user")).getUserId();
		try {
			int supId = supplierService.getSupIdByUserId(userId);
			String userTestValue = userService.getUserTestValueForSuppOrder(orderDate, supId);
			json.put("stringJson", userTestValue);

		} catch (GenericException e) {
			e.printStackTrace();
		}
		return json.toString();
	}

	// 分货 检索客户列表
	@RequestMapping(value = "/shopForSuppOrderDistribute.do", method = { RequestMethod.POST })
	@ResponseBody
	public String userTestValueForSuppOrderDistribute(String orderDate, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		long userId = ((UserPo) session.getAttribute("user")).getUserId();
		try {
			int supId = supplierService.getSupIdByUserId(userId);
			String userTestValue = userService.getUserTestValueForSuppOrderDistribute(orderDate, supId);
			json.put("stringJson", userTestValue);

		} catch (GenericException e) {
			e.printStackTrace();
		}
		return json.toString();
	}

	@RequestMapping(value = "/pullDownProvince.do", method = { RequestMethod.POST })
	@ResponseBody
	public String pullDownProvince(String space) {
		String provicePullJson = "";
		try {
			provicePullJson = userService.getPullDownProvince(space);
		} catch (GenericException e) {
			e.printStackTrace();
		}
		return provicePullJson;
	}

	@RequestMapping(value = "/pullDownCity.do", method = { RequestMethod.POST })
	@ResponseBody
	public String pullDownCity(LdAddressVo ldAddressVo, String space) {
		String proviceCityJson = "";
		try {
			proviceCityJson = userService.getPullDownCity(ldAddressVo.getParentId(), space);
		} catch (GenericException e) {
			e.printStackTrace();
		}
		return proviceCityJson;
	}

	@RequestMapping(value = "/pullDownCountry.do", method = { RequestMethod.POST })
	@ResponseBody
	public String pullDownCountry(LdAddressVo ldAddressVo, String space) {
		String proviceCountryJson = "";
		try {
			proviceCountryJson = userService.getPullDownCountry(ldAddressVo.getParentId(), space);
		} catch (GenericException e) {
			e.printStackTrace();
		}
		return proviceCountryJson;
	}

	/**
	 * 核心请求处理类
	 * 
	 * @author liufeng
	 * @date 2013-05-18
	 * 
	 *       确认请求来自微信服务器
	 */
	@RequestMapping(value = "/weixin.do", method = RequestMethod.GET)
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 微信加密签名
		String signature = request.getParameter("signature");
		// 时间戳
		String timestamp = request.getParameter("timestamp");
		// 随机数
		String nonce = request.getParameter("nonce");
		// 随机字符串
		String echostr = request.getParameter("echostr");

		PrintWriter out = response.getWriter();
		// 通过检验signature对请求进行校验，若校验成功则原样返回echostr，表示接入成功，否则接入失败
		if (SignUtil.checkSignature(signature, timestamp, nonce)) {
			out.print(echostr);
		}
		out.close();
		out = null;
	}

	@RequestMapping(value = "/weixin.do", method = RequestMethod.POST)
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8"); // 微信服务器POST消息时用的是UTF-8编码，在接收时也要用同样的编码，否则中文会乱码；
		response.setCharacterEncoding("UTF-8"); // 在响应消息（回复消息给用户）时，也将编码方式设置为UTF-8，原理同上；
		response.setContentType("text/html;charset=utf-8");
		// 初始化配置文件
		String respMessage = "正在维护请稍微使用。";
		try {
			respMessage = coreService.processRequest(request);
		} catch (GenericException e) {
			e.printStackTrace();
			log.info(e.toString());
		}// 调用CoreService类的processRequest方法接收、处理消息，并得到处理结果；
			// 响应消息
		PrintWriter out = null;
		out = response.getWriter();
		out.print(respMessage);
		out.close();
	}

	@RequestMapping(value = "/userLevelPullDown.do", method = { RequestMethod.POST })
	@ResponseBody
	public String userLevelPullDown(String space) {
		String userLevelString = "";
		try {
			userLevelString = dataDictionaryService.pullDownListDiy("userLevel", "levelId", "levelName", space);
		} catch (GenericException e) {
			e.printStackTrace();
		}
		return userLevelString;
	}

	@RequestMapping(value = "/userlevel.do", method = { RequestMethod.POST })
	@ResponseBody
	public String userlevel(UserVo userVo, HttpServletRequest request, HttpServletResponse response) {
		String userLevel = "";
		try {
			response.setContentType("text/html;charset=UTF-8");
			userLevel = userService.getUserLevel(userVo);

		} catch (GenericException e) {
			e.printStackTrace();
		}

		return userLevel;
	}

	// 用户录入界面 关于上级领导的查询
	@RequestMapping(value = "/userlevelChina.do", method = { RequestMethod.POST })
	@ResponseBody
	public String userlevelChina(UserVo userVo, HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		String userLevel = "";
		try {
			response.setContentType("text/html;charset=UTF-8");
			userLevel = userService.getUserLevel(userVo);
			if (userLevel.equals("")) {
				json.put("success", true);
				return json.toString();
			}

		} catch (GenericException e) {
			e.printStackTrace();
		}

		response.setHeader("Cache-Control", "no-cache");
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out;
		try {
			out = response.getWriter();
			out.write(userLevel);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return userLevel;
	}

	// 检索页面关于店长的查询
	@RequestMapping(value = "/checkCustlook.do", method = { RequestMethod.POST })
	@ResponseBody
	public String checkCustlook(UserVo userVo, HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		String userLevel = "";
		try {
			response.setContentType("text/html;charset=UTF-8");
			userLevel = userService.getCheckCust(userVo);
			if (userLevel.equals("")) {
				json.put("success", true);
				return json.toString();
			}

		} catch (GenericException e) {
			e.printStackTrace();
		}

		response.setHeader("Cache-Control", "no-cache");
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out;
		try {
			out = response.getWriter();
			out.write(userLevel);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return userLevel;
	}

	@RequestMapping(value = "/checkUserName.do", method = { RequestMethod.POST })
	@ResponseBody
	public String checkUserName(String value) {
		JSONObject json = new JSONObject();
		try {
			boolean flag = userService.getUserNameForCheck(value);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("success", false);
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}

	@RequestMapping(value = "/checkRealName.do", method = { RequestMethod.POST })
	@ResponseBody
	public String checkRealName(String value) {
		JSONObject json = new JSONObject();
		try {
			boolean flag = userService.getRealNameForCheck(value);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("success", false);
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}

	@RequestMapping(value = "/checkPhone.do", method = { RequestMethod.POST })
	@ResponseBody
	public String checkPhone(String value) {
		JSONObject json = new JSONObject();
		try {
			boolean flag = userService.getCheckPhone(value);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("success", false);
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}
}
